Answer the following questions and complete the exercises in
RMarkdown. Please embed all of your code and push your final work to
your repository. Your final lab report should be organized, clean, and
run free from errors. Remember, you must remove the # for
the included code chunks to run. Be sure to add your name to the author
header above. For any included plots, make sure they are clearly
labeled. You are free to use any plot type that you feel best
communicates the results of your analysis.
Make sure to use the formatting conventions of RMarkdown to make your report neat and clean!
library(tidyverse)
library(janitor)
library(ggmap)
register_stadiamaps("d67f62a2-bd90-430c-a40a-9ad6e095b888", write = FALSE)
We will use two separate data sets for this homework.
The first data set represent sightings of grizzly bears (Ursos arctos) in Alaska.
The second data set is from Brandell, Ellen E (2021), Serological dataset and R code for: Patterns and processes of pathogen exposure in gray wolves across North America, Dryad, Dataset.
Load the grizzly data and evaluate its
structure.
grizzly <- read_csv("data/bear-sightings.csv") %>%
clean_names()
## Rows: 494 Columns: 3
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## dbl (3): bear.id, longitude, latitude
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
grizzly %>%
select(longitude, latitude) %>%
summary()
## longitude latitude
## Min. :-166.2 Min. :55.02
## 1st Qu.:-154.2 1st Qu.:58.13
## Median :-151.0 Median :60.97
## Mean :-149.1 Mean :61.41
## 3rd Qu.:-145.6 3rd Qu.:64.13
## Max. :-131.3 Max. :70.37
lat <- c(55.02, 70.37)
long <- c(-166.2, -131.3)
bbox <- make_bbox(long, lat, f=0.03)
stamen in a terrain style projection
and display the map.map1 <- get_stadiamap(bbox, maptype = "stamen_terrain", zoom=7)
## ℹ © Stadia Maps © Stamen Design © OpenMapTiles © OpenStreetMap contributors.
## ℹ 196 tiles needed, this may take a while (try a smaller zoom?)
ggmap(map1)
ggmap(map1) +
geom_point(data=grizzly, aes(longitude, latitude), size = 0.5)+
labs(x = "Longitude",
y = "Latitude",
title = "Grizzly Observations")
Let’s switch to the wolves data. Brandell, Ellen E (2021), Serological dataset and R code for: Patterns and processes of pathogen exposure in gray wolves across North America, Dryad, Dataset.
wolves <- read_csv("data/wolves_data/wolves_dataset.csv")
## Rows: 1986 Columns: 23
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (4): pop, age.cat, sex, color
## dbl (19): year, lat, long, habitat, human, pop.density, pack.size, standard....
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
str(wolves)
## spc_tbl_ [1,986 × 23] (S3: spec_tbl_df/tbl_df/tbl/data.frame)
## $ pop : chr [1:1986] "AK.PEN" "AK.PEN" "AK.PEN" "AK.PEN" ...
## $ year : num [1:1986] 2006 2006 2006 2006 2006 ...
## $ age.cat : chr [1:1986] "S" "S" "A" "S" ...
## $ sex : chr [1:1986] "F" "M" "F" "M" ...
## $ color : chr [1:1986] "G" "G" "G" "B" ...
## $ lat : num [1:1986] 57 57 57 57 57 ...
## $ long : num [1:1986] -158 -158 -158 -158 -158 ...
## $ habitat : num [1:1986] 254 254 254 254 254 ...
## $ human : num [1:1986] 10.4 10.4 10.4 10.4 10.4 ...
## $ pop.density : num [1:1986] 8 8 8 8 8 8 8 8 8 8 ...
## $ pack.size : num [1:1986] 8.78 8.78 8.78 8.78 8.78 8.78 8.78 8.78 8.78 8.78 ...
## $ standard.habitat : num [1:1986] -1.63 -1.63 -1.63 -1.63 -1.63 ...
## $ standard.human : num [1:1986] -0.978 -0.978 -0.978 -0.978 -0.978 ...
## $ standard.pop : num [1:1986] -0.683 -0.683 -0.683 -0.683 -0.683 ...
## $ standard.packsize : num [1:1986] 1.32 1.32 1.32 1.32 1.32 ...
## $ standard.latitude : num [1:1986] 0.721 0.721 0.721 0.721 0.721 ...
## $ standard.longitude: num [1:1986] -2.14 -2.14 -2.14 -2.14 -2.14 ...
## $ cav.binary : num [1:1986] 1 1 1 0 1 1 1 1 1 1 ...
## $ cdv.binary : num [1:1986] 0 0 0 0 0 1 0 0 0 0 ...
## $ cpv.binary : num [1:1986] 0 0 1 1 0 1 0 0 0 0 ...
## $ chv.binary : num [1:1986] 1 1 1 1 1 1 1 1 1 0 ...
## $ neo.binary : num [1:1986] NA NA NA 0 0 NA NA 1 0 1 ...
## $ toxo.binary : num [1:1986] NA NA NA 1 0 NA NA 1 0 0 ...
## - attr(*, "spec")=
## .. cols(
## .. pop = col_character(),
## .. year = col_double(),
## .. age.cat = col_character(),
## .. sex = col_character(),
## .. color = col_character(),
## .. lat = col_double(),
## .. long = col_double(),
## .. habitat = col_double(),
## .. human = col_double(),
## .. pop.density = col_double(),
## .. pack.size = col_double(),
## .. standard.habitat = col_double(),
## .. standard.human = col_double(),
## .. standard.pop = col_double(),
## .. standard.packsize = col_double(),
## .. standard.latitude = col_double(),
## .. standard.longitude = col_double(),
## .. cav.binary = col_double(),
## .. cdv.binary = col_double(),
## .. cpv.binary = col_double(),
## .. chv.binary = col_double(),
## .. neo.binary = col_double(),
## .. toxo.binary = col_double()
## .. )
## - attr(*, "problems")=<externalptr>
wolves_2 <- wolves %>%
filter(lat<= 49.38)
wolves_2 %>%
count(pop)
## # A tibble: 6 × 2
## pop n
## <chr> <int>
## 1 GTNP 60
## 2 MEXICAN 181
## 3 MI 102
## 4 MT 351
## 5 SNF 92
## 6 YNP 383
wolves_2 %>%
select(long, lat) %>%
summary()
## long lat
## Min. :-110.99 Min. :33.89
## 1st Qu.:-110.99 1st Qu.:44.60
## Median :-110.55 Median :44.60
## Mean :-106.91 Mean :43.95
## 3rd Qu.:-109.17 3rd Qu.:46.83
## Max. : -86.82 Max. :47.75
lat_2 <- c(33.89, 47.75)
long_2 <- c(-110.99, -86.82)
bbox_2 <- make_bbox(long_2, lat_2, f=0.03)
stamen in a terrain-lines
projection and display the map.map_2 <- get_stadiamap(bbox_2, maptype = "stamen_terrain", zoom=7)
## ℹ © Stadia Maps © Stamen Design © OpenMapTiles © OpenStreetMap contributors.
## ℹ 80 tiles needed, this may take a while (try a smaller zoom?)
ggmap(map_2)
ggmap(map_2) +
geom_point(data=wolves_2, aes(long, lat), size = 2)+
labs(x = "Longitude",
y = "Latitude",
title = "Wolves' Observations")
fill and color by population.ggmap(map_2) +
geom_point(data=wolves_2, aes(long, lat, color = pop), size = 2)+
labs(x = "Longitude",
y = "Latitude",
title = "Wolves' Observations")
Please be sure that you check the keep md file in the
knit preferences.